<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<%@ taglib prefix="his_fns" uri="/WEB-INF/tlds/his_fns.tld" %>
<script>
    var ctx = '${ctx}';
    $(function () {
        heightWidthDoctor();
        function heightWidthDoctor() {
            var bodyHeight = $("body").height();
            var footerHeight = $("#footerId").height();
            var headerHeight = $("#headerId").height();
            var patientDivHeight = $("#patientDiv").height();
            var d1 = $("#d1").height();
            var d2 = $("#d2").height();
            var d3 = $("#d3").height();
            var d4 = $("#d4").height();
            var d5 = $("#tags").height();
            var d6 = $("#footSearchId").height();
//            alert(patientDivHeight-d1-d2-d3-d4-d5-d6-105);
            $("#resultNav").height(patientDivHeight - d1 - d2 - d3 - d4 - d5 - d6 - 105);

            var doctorUl = $("#doctorUlId").height();
            $("#rigthDoctorCenterDiv").height(bodyHeight - footerHeight - headerHeight - doctorUl);
        }

        queryPatientTj('0');
    })

    /**
     * 切换体检操作界面
     * @param url
     * @param li
     */
    function loadDoctorDiv(url, li) {
        var patientId = $("#patientId").val();
        var clinicId = $("#clinicId").val();
        var deptId = $("#deptId").val();
        var deptName = $("#deptName").val();
        if(checkParams(patientId,clinicId,li)){
            url = url + "?patientId=" + patientId + "&clinicId=" + clinicId+"&deptId="+deptId+"&deptName="+deptName;
            loadDiv('rigthDoctorCenterDiv', url)
            $("#doctorUlId li").removeClass("active");
            $(li).parent().addClass("active");
        }else{
            toastr.error("请先选择病人！");
        }
    }


    //校验参数是否获取到
    function checkParams(patientId,clinicId,selfObj){
        if(patientId==null || patientId==""){
            toastr.error("请先选择病人!");
            return false;
        }
        if(clinicId==null || clinicId==""){
            toastr.error("获取病人就诊记录id失败！");
            return false;
        }
        $(selfObj).parent().parent().find("li").attr("class","");
        $(selfObj).parent().attr("class","active");
        return true;
    }

    function addUser() {
        layer.open({
            type: 2,
            title: '体检病人添加',
            area: ['1200px', '550px'],
            fixed: false, //不固定
            maxmin: true,
            name: "template",
            content: ctx + '/physical/addphyUser'
        });
    }

    /**
     *个检、团检切换
     * */
    function selectTag(type, selfObj) {
        $(selfObj).parent().parent().find("li").removeClass("selectTag")
        $(selfObj).parent().addClass("selectTag");
        queryPatientTj('0');

    }

    /**
     *患者列表加载
     * */
    function queryPatientTj(plus) {
        if(plus=="0"){
            $("#resultShow").html("");
        }
        var fj = $("input[name='fj']:checked").val();
        var zj = $("input[name='zj']:checked").val();
        var sf = $("input[name='sf']:checked").val();
        var type = $("#tags .selectTag").attr("type");
        var requestParams = {fj: fj, zj: zj, sf: sf, type: type};
        $.ajax({
            data: requestParams,
            type: "post",
            url: '${ctx}/physical/queryPatientTj',
            dataType: "json",
            success: function (data) {
                if (data.list.length > 0) {
                    $("#resultShow").append(appendDataStr(data));
                    if (plus == "0") {
                        $("#resultShow li:first").click();
                    }
                }
            }
        })
    }

    /**
     *  拼接返回的json列表
     * @param data   json 字符串
     */
    function appendDataStr(data) {
        var returnStr = "";
        for (var i = 0; i < data.list.length; i++) {
            returnStr += "<li class='selected'><a href='#' onclick='setPatientValue(\""+data.list[i].id+"\",\""+data.list[i].clinicId+"\",this)' class='btn btn-success btn-xs'> <div class='clearfix' style='padding-right:5px;'><span class='pull-left'>" + data.list[i].name + "</span> <span class='pull-right'><span class='gray-b color-white'>分</span><span class='red-b color-white'>总</span><span class='gray-b color-white'>收</span></span></div> <div class='clearfix' style='padding-right:5px;'> <span class='pull-left'>&nbsp;" + data.list[i].sex + "&nbsp;&nbsp;" + data.list[i].age + "岁</span> <span class='pull-right'>门诊号：" + data.list[i].clinicNo + "</span> </div></a></li>"
        }
        return returnStr;
    }

    function setPatientValue(patientId,clinicId,li){
        $("#patientId").val(patientId);
        $("#clinicId").val(clinicId);
        $(li).parent().find("li").attr("class","");
        $(li).attr("class","selected");
        $("#doctorUlId li:first a:first").click();
    }
</script>
<div class="app">
    <section class="layout">
        <!-- sidebar menu -->

        <!-- /sidebar menu -->

        <!-- mail sidebar navigation -->
        <aside class="sidebar-230 canvas-right bg-default ">
            <header class="header navbar clearfix bb bg-default pl0 pr0 header-h" id="innerHead">
                <p class="navbar-text mh">体检患者列表</p>

                <div class="btn-group pull-right mr10 mt2">
                    <button type="button" class="btn btn-sm" onclick="addUser()">
                        <i class="fa fa-plus-square"></i>
                    </button>
                </div>
            </header>
            <div class="content-wrap no-p">

                <div class="wrapper wrapper-p34" id="patientDiv">
                    <div class="choice-wrap" id="d1">
                        <ul>
                            <li><span class="gray-b span-b-w"></span>未开始</li>
                            <li><span class="green-b span-b-w"></span>进行中</li>
                            <li><span class="red-b span-b-w"></span>已结束</li>
                        </ul>
                    </div>
                    <div class="choice-wrap h30" id="d2">
                        <label>分检：</label>
                        <ul class="ul-w">
                            <li><input type="radio" onclick="queryPatientTj('0')" name="fj" checked="checked" value="0">未开始
                            </li>
                            <li><input type="radio" onclick="queryPatientTj('0')" name="fj" value="1">进行中</li>
                            <li><input type="radio" onclick="queryPatientTj('0')" name="fj" value="2">已结束</li>
                        </ul>
                    </div>
                    <div class="choice-wrap h30" id="d3">
                        <label>总检：</label>
                        <ul class="ul-w">
                            <li><input type="radio" onclick="queryPatientTj('0')" name="zj" checked="checked" value="0">未开始
                            </li>
                            <li><input type="radio" onclick="queryPatientTj('0')" name="zj" value="1">进行中</li>
                            <li><input type="radio" onclick="queryPatientTj('0')" name="zj" value="2">已结束</li>
                        </ul>
                    </div>
                    <div class="choice-wrap h30" id="d4">
                        <label>收费：</label>
                        <ul class="ul-w">
                            <li><input type="radio" onclick="queryPatientTj('0')" name="sf" checked="checked" value="0">未收费
                            </li>
                            <li><input type="radio" onclick="queryPatientTj('0')" name="sf" value="1">已收费</li>
                        </ul>
                    </div>
                    <ul class="clearfix tags_new tags_bl" id="tags">
                        <li class="selectTag" type="0">
                            <A checked="checked" onClick="selectTag('0',this)"
                               href="javascript:void(0)">个检人员</A></li>
                        <li type="1"><A onClick="selectTag('1',this)"
                                         href="javascript:void(0)">团检人员</A></li>
                    </ul>
                    <nav role="navigation" id="resultNav" style="overflow:auto">
                        <div class="no-padding">
                            <ul class="nav nav-stacked" id="resultShow">

                            </ul>
                            <%--<a id='loadMoreBtn' href="#">加载更多</a>--%>
                            <div class="foot-search" id="footSearchId">
                                <input type="text" class="sear-input" id="likeText">
                                <button id='searchBtn' class="sear-btn">搜索</button>
                            </div>
                        </div>
                    </nav>
                </div>
            </div>
        </aside>
        <!-- /mail sidebar navigation -->

        <!-- main content -->
        <section class="main-content" id="doctorSectionId">
            <div class="content-wrap">
                <div class="wrapper">
                    <ul class="nav nav-tabs" id="doctorUlId">
                        <li class="active">
                            <a href="#" onclick="loadDoctorDiv('${ctx}/physical/userBasicInfo',this)">基本信息</a>
                        </li>
                        <li>
                            <a href="#" onclick="loadDoctorDiv('${ctx}/physical/itemInput',this)">项目录入</a>
                        </li>
                        <li>
                            <a href="#" onclick="loadDoctorDiv('${ctx}/physical/sorting/',this)">分检</a>
                        </li>
                        <li>
                            <a href="#" onclick="loadDoctorDiv('${ctx}/totalInspection/index',this)">总检</a>
                        </li>
                    </ul>
                    <div class="row bg-color" style="overflow: auto" id="rigthDoctorCenterDiv">

                    </div>
                </div>
            </div>
        </section>
        <!-- /main content -->
        <input type="hidden" id="patientId" name="patientId" value=""/>
        <input type="hidden" id="clinicId" name="clinicId" value=""/>
        <input type="hidden" id="deptName" name="deptId" value="${orgDept.deptName}"/>
        <input type="hidden" id="deptId" name="deptName" value="${orgDept.id}"/>
    </section>
</div>

